<?php 

namespace app\common\shop;

use think\Db;
use think\Model;
use traits\model\SoftDelete;


class UserApplyLogModel extends model {
    //use SoftDelete;//开启了软删除
    //protected  = 'del_time';
    // 完整数据表名
    protected $table = 'user_apply_log';


    /**
     * [建表]
     * @return
     */
    public static function createTable(){
        return Db::query("CREATE TABLE If Not Exists `user_apply_log` (
              `id` int(11) NOT NULL AUTO_INCREMENT,
              `uid` int(11) NOT NULL COMMENT '会员id',
              `leveltype` int(11) NOT NULL COMMENT '身份类型',
              `levelid` int(11) NOT NULL DEFAULT '0' COMMENT '申请身份等级',
              `name` varchar(255) NOT NULL DEFAULT '0' COMMENT '姓名',
              `province` varchar(255) NULL DEFAULT NULL COMMENT '省',
              `city` varchar(255) NULL DEFAULT NULL COMMENT '市',
              `area` varchar(255) NULL DEFAULT NULL COMMENT '区域代理',
              `status` int(11) NOT NULL DEFAULT '0' COMMENT '状态',
              `createtime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '时间',
              `finishtime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '审核时间',
              PRIMARY KEY (`id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='身份申请表'");
    }

 	/**
     * [添加]
     * @return
    */
    public static function add($data){
    	$data['createtime'] = time();
    	return self::insertGetId($data);
    }



    public function getLevelTypeName($leveltype){
        switch ($leveltype){
            case 1:
                return '团长';
                break;
            case 2:
                return '代理商';
                break;
            case 3:
                return '房主';
                break;
            case 4:
                return '区域代理';
                break;
            default:
                return '';
        }
    }
    /**
     * [身份等级]
     * @param
     * @return
     */
    public function leveldata( $leveltype,$levelid ){
        $level = [];
        switch ($leveltype){
            case 1:
                $level = UserTeamLevelModel::field('id,name')->order('id asc')->select()->toArray();
                break;
            case 2:
                $level = UserAgentLevelModel::field('id,name')->order('id asc')->select()->toArray();
                break;
            case 3:
                $level = UserHouseLevelModel::field('id,name')->order('id asc')->select()->toArray();
                break;
            case 4:
                $level = UserAreaLevelModel::field('id,name')->order('id asc')->select()->toArray();
                break;
            default:
                return '';
        }
        foreach($level as $k=>$v){
            if($v['id'] == $levelid){
                return $v['name'];
            }
        }
        return '';
    }
}